package com.mingmen.supplier.activity;


import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.imagepicker.ImagePicker;
import com.mingmen.supplier.R;
import com.mingmen.supplier.adapter.WeiHuListAdapter;
import com.mingmen.supplier.http.callback.StringCallback;
import com.mingmen.supplier.httpconfig.HttpResponse;
import com.mingmen.supplier.immersionbar.ImmersionBar;
import com.mingmen.supplier.util.SharePreferenceUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class MyWeiHuListActivity extends AppCompatActivity implements WeiHuListAdapter.OnItemClickListener {

    //返回按钮
    @BindView(R.id.text_return)
    TextView textReturn;

    private ImagePicker imagePicker;

    @BindView(R.id.btn_login)
    Button btn_login;

    private int resurtResurant = 100;
    @BindView(R.id.recycle_shopo)
    RecyclerView mRecyclerView;

    WeiHuListAdapter commodityAdapter;

    List<String> dataList = new ArrayList<>();

    LinearLayoutManager linearLayoutManager;


    @BindView(R.id.view_dishline)
    View view_dishline;

    String token;
    String jdataData;
    String date_Send;
    String categoryId;
    @BindView(R.id.linear_return)
    LinearLayout linear_return;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_myweihu);
        ButterKnife.bind(this);
        ImmersionBar.with(this)
                .statusBarDarkFont(true, 0.2f)
                .init();
        linearLayoutManager = new LinearLayoutManager(this);
        token = (String) SharePreferenceUtil.get(this, "token", "");
//        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4);
        jdataData = getIntent().getStringExtra("jdataData");
        categoryId = getIntent().getStringExtra("categoryId");
        mRecyclerView.setLayoutManager(linearLayoutManager);
        commodityAdapter = new WeiHuListAdapter(this, dataList);
        mRecyclerView.setAdapter(commodityAdapter);
        for (int i = 0; i < 10; i++) {
            dataList.add("ITem" + i);
        }
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));
        date_Send = formatter.format(date);
        Log.d("categoryId", categoryId);
        Log.d("jdataData", jdataData);
        HttpResponse.setPrice(token, date_Send, categoryId, jdataData, new StringCallback(this) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("setPricesetPrice", s);
            }
        });

        commodityAdapter.setDataList(dataList);
        commodityAdapter.setOnItemClickListener(this);
/*   HttpResponse.listCommodityByDate(token, date_Send, "", new StringCallback(this) {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                Log.d("WeihuListActivity", s);
                WeiHuModel weiHuModel = new WeiHuModel();
                weiHuModel = GsonUtil.GsonToBean(s, WeiHuModel.class);
//                dataList.addAll(weiHuModel.getData());
                commodityAdapter.setDataList(dataList);
            }
        });*/

        Bitmap bitmap = ((BitmapDrawable) getResources().getDrawable(R.mipmap.arrowblue_bottom)).getBitmap();
        Matrix matrix = new Matrix();
        matrix.setRotate(180);
        bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);


        commodityAdapter.setOnItemClickListener(new WeiHuListAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(View view, int pos, List<String> myLiveList) {
                switch (view.getId()) {
                    case R.id.text_manager:
                        startActivity(new Intent(MyWeiHuListActivity.this, CommodityShopManagerActivity.class));
                        break;
                    default:
                        startActivity(new Intent(MyWeiHuListActivity.this, NoticeDetailActivity.class));
                }
            }
        });

    }


    @OnClick({R.id.text_return, R.id.btn_login, R.id.linear_return})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.text_return:
                finish();
                break;
            case R.id.btn_login:
                startActivity(new Intent(MyWeiHuListActivity.this, NoticeSendActivity.class));

                break;
            case R.id.linear_return:

                finish();
                break;
        }
    }


    @Override
    public void onItemClickListener(View view, int pos, List<String> myLiveList) {

    }

}




